﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Tools;
using DAL;
namespace BLL
{
    public class ManageBooksBLL
    {
        #region 图书类型表
        //图书类型集合
        public static List<BookType> BookTypeList()
        {
            return ManageBooksDAL.BookTypeList();
        }

        //删除图书类型
        public static void RemoveBookType(int id)
        {
            ManageBooksDAL.RemoveBookType(id);
        }

        //添加图书类型
        public static string AddBookType(BookType item)
        {
            if (item.TypeName == null || item.TypeName.Length > 50)
            {
                return "类型名称为空或过长";
            }
            else
            {
                ManageBooksDAL.AddBookType(item);
                return "添加成功";
            }

        }

        //修改图书类型
        public static string EditBookType(BookType item)
        {
            if (item.TypeName == null || item.TypeName.Length > 50)
            {
                return "类型名称为空或过长";
            }
            else
            {
                ManageBooksDAL.EditBookType(item);
                return "修改成功";
            }
        }
        #endregion

        #region 图书信息表
        //图书信息集合
        public static List<BookInfo> BookInfoList()
        {
            return ManageBooksDAL.BookInfoList();
        }

        //删除图书
        public static void RemoveBookInfo(int id)
        {
            ManageBooksDAL.RemoveBookInfo(id);
        }
        //图书信息添加
        public static string AddBookInfo(BookInfo item)
        {
            if (item.Author == null || item.BookDesc == null || item.BookName == null || item.BookNum == null || item.OriginalPrice.ToString() == null || item.Pubishing == null || item.PublicaDate == null || item.TypeID.ToString() == null)
            {
                return "图书信息不能为空";
            }
            else
            {
                ManageBooksDAL.AddBookInfo(item);
                return "添加成功";
            }
        }
        public static string EditBookInfo(BookInfo item)
        {
            BookInfo item1 = ManageBooksDAL.BookInfoList().Where(a => a.BookID == item.BookID).SingleOrDefault();
            if (item.PresentPrice != item1.PresentPrice)
            {
                item.OriginalPrice = item1.PresentPrice;
            }
            if (item.Author == null || item.BookDesc == null || item.BookName == null || item.BookNum == null || item.PresentPrice.ToString() == null || item.Pubishing == null || item.PublicaDate == null || item.TypeID.ToString() == null)
            {
                return "图书信息不能为空";
            }
            else
            {
                ManageBooksDAL.EditBookInfo(item);
                return "修改成功";
            }
        }
        //添加图片
        public static void AddBookPic(string PicUrl, int id = 0)
        {
            ManageBooksDAL.AddBookPic(PicUrl, id);
        }
        #endregion
        #region 图书信息表
        public static List<Comments> BookComList()
        {
            return ManageBooksDAL.BookComList();
        }
        #endregion
    }
}
